<?php
	include "inc/inc_header1.php"; // header
	include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/conn_db.php");
	include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/Utils.php");

	if(isset($_POST['username'])){
		$username = $_POST['username'];
	}
	if(isset($_POST['password'])){
		$password = $_POST['password'];
	}
	$login = "/login.php";
	$index = "/index01.php";
	if(isset($_COOKIE['user'])){
		$username = $_COOKIE['user'];
	}else{
		if($username && $password){
			$islogin = Utils::login($username, $password);
			if($islogin == "succ"){
				setcookie("user", $username);
			}
		}
	}

	$type = Utils::getUserType($_COOKIE['user']);
	if($type == -1){
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.href='$login'";
		echo "</script>";
	}else if($type != 1){
		echo "<script language='javascript' type='text/javascript'>";
		echo "window.location.href='$index'";
		echo "</script>";
	}
?>
<script language="javascript" type="text/javascript">
	$(document).ready(function(){
		$("#first_name").change(function(){
			$("#last_name").html("<option value=''>선택</option>");
			$("#home").html("<option value=''>선택</option>");
			var index = $(this).children('option:selected').val();
			if(index){
				$.ajax({
					type:'get',
					url:'getcategory.php',
					data:{index: index},
					success:function(msg){
						var data = eval("(" + msg + ")");
						if(data.status == "logout"){
							window.location.href='/login.php';
						}
						var html = "<option value=''>선택</option>";
						for(var i = 0; i < data.length; i ++){
							var param = data[i];
							html += "<option value='" + (i + 1) + "' left='" + param.left + "' right='" + param.right + "'>" + param.name + "(" + param.hname + ")</option>";
						}
						$("#last_name").html(html);
					}
				});
			}
		});

		$("#last_name").change(function(){
			$("#home").html("<option value=''>선택</option>");
			var option = $(this).children('option:selected');
			var left = option.attr("left");
			var right = option.attr("right");
			if(option.val()){
				$.ajax({
					type:'get',
					url:'getcategory.php',
					data:{type:1, left: left, right: right},
					success:function(msg){
						var data = eval("(" + msg + ")");
						if(data.status == "logout"){
							window.location.href='/login.php';
						}
						var html = "<option value=''>선택</option>";
						for(var i = 0; i < data.length; i ++){
							var param = data[i];
							html += "<option value='" + param.id + "'>" + param.name + (param.hname ? ("(" + param.hname + ")") : "") + "</option>";
						}
						$("#home").html(html);
					}
				});
			}
		});

		$("#type").change(function(){
			var option = $(this).children('option:selected');
			$("#parent").html("<option value=''>선택</option>");
			var type = option.val();
			var home = $("#home").children('option:selected').val();
			if(type > 1 && home){
				$.ajax({
					type:'get',
					url:'getcategory.php',
					data:{type:2, gen_type: type, code:home},
					success:function(msg){
						var data = eval("(" + msg + ")");
						if(data.status == "logout"){
							window.location.href='/login.php';
						}
						var html = "<option value=''>선택</option>";
						for(var i = 0; i < data.length; i ++){
							var param = data[i];
							html += "<option value='" + param.id + "'>" + param.cate_name + (param.cate_hname ? ("(" + param.cate_hname + ")") : "") + "</option>";
						}
						$("#parent").html(html);
					}
				});
			}
		});

		$("#submit").click(function(){
			$.ajax({
				type:'post',
				url:'getcategory.php',
				data:{type:3, gen:$("#gen").val(), cate_name:$("#cate_name").val(), cate_hname:$("#cate_hname").val(), pa_type:$("#type").val(), pa_name:$("#pa_name").val(), pa_hname:$("#pa_hname").val(), parent:$("#parent").val(), home:$("#home").val()},
				success:function(msg){
					var data = eval("(" + msg + ")");
					if(data.status == "succ"){
						alert("添加成功");
					}else{
						alert("数据有误");
					}

				}
			});
		});
	});
</script>
</head>
<body class="admin_bd">
    <div id="header">
        <div class="inner">
            <div class="logo"><img src="../img/logo.png"/></div>
            <div class="login">尊敬的<span class="orgs"><?php echo $username;?></span>，下午好！<a href="/logout.php">[退出]</a></div>
        </div>
    </div>
    <div class="wrap">
        <div class="container clearfix">
            <div class="bs-docs-sidebar">
                <ul class="nav-list">
                    <li class="active"><a href="#typography"><i class="icon-chevron-right"></i>EDIT PA</a></li>
                    <li><a href="#code"><i class="icon-chevron-right"></i>user_info2</a></li>
                </ul>
            </div>
            <div class="main_col">
                <div class="page-header">
                    <h2>EDIT PA</h2>
                </div>
                <table width="100%" cellspacing="1" cellpadding="0" class="table_form">
                    <tr>
                        <td class="tr" width="100">초성：</td>
                        <td>
                            <select id="first_name" name="first_name" class="f_select">
                                <option value="0">선택</option>
                                <option value="1">ㄱ</option>
                                <option value="2">ㄴ</option>
                                <option value="3">ㄷ</option>
                                <option value="4">ㄹ</option>
                                <option value="5">ㅁ</option>
                                <option value="6">ㅂ</option>
                                <option value="7">ㅅ</option>
                                <option value="8">ㅇ</option>
                                <option value="9">ㅈ</option>
                                <option value="10">ㅊ</option>
                                <option value="11">ㅋ</option>
                                <option value="12">ㅌ</option>
                                <option value="13">ㅍ</option>
                                <option value="14">ㅎ</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="tr">성씨：</td>
                        <td>
                            <select id="last_name" name="last_name" class="f_select">
                                <option value="">선택</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="tr">본관：</td>
                        <td>
                            <select id="home" name="home" class="f_select">
                                <option value="">선택</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="tr">世：</td>
                        <td><input type="text" class="f_text" id="gen" name="gen"/></td>
                    </tr>
                    <tr>
                        <td class="tr">名：</td>
                        <td><input type="text" class="f_text" id="cate_name" name="cate_name"/></td>
                    </tr>
					<tr>
                        <td class="tr">名(汉)：</td>
                        <td><input type="text" class="f_text" id="cate_hname" name="cate_hname"/></td>
                    </tr>
					<tr>
                        <td class="tr">派系：</td>
                        <td>
							<select id="type" name="type" class="f_select">
                                <option value="0">선택</option>
								<option value="1">대파(大派)</option>
								<option value="2">중파(中派)</option>
								<option value="3">지파(小派)</option>
								<option value="3">지파(支派)</option>
								<option value="4">입향조(门中派)</option>
                            </select>
						</td>
                    </tr>
					<tr >
                        <td class="tr">父辈：</td>
                        <td>
							<select id="parent" name="parent" class="f_select">
                                <option value="">선택</option>
                            </select>
						</td>
                    </tr>
					<tr>
                        <td class="tr">派名：</td>
                        <td><input type="text" class="f_text" id="pa_name" name="pa_name"/></td>
                    </tr>
					<tr>
                        <td class="tr">派名(汉)：</td>
                        <td><input type="text" class="f_text" id="pa_hname" name="pa_hname"/></td>
                    </tr>
                    <tr>
                        <td class="tr">&nbsp;</td>
                        <td><input name="submit" id="submit" type="button" value="submit" class="btn btn-info" style="width:80px;">
                            &nbsp;</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
<?php include "inc/inc_bottom.php" ?><!-- bottom -->
<?php include "inc/inc_footer.php" ?><!-- footer -->
